
//THIS CODE FILE PRODUCES FIGURE A.8, FIGURE A.9, FIGURE A.10, AND FIGURE A.11

global main "[YOUR PATH HERE]"
global output "${main}/output"


//switch to rerun the build stacked data do file
local switch_rerun_stacking = 0

local switch_all = 0
local switch_nponly  = 0
local switch_fponly  = 0
local switch_pubonly = 1
local switch_post00  = 0

		
local switch_controls = 0
if `switch_controls'{
	local controls "free_cc unemp_rate"
	local control_lab "_controls"
}
	
local pop t //w m //this lets us run men women or total enrollment by race
	
********************************************************************************
**CREATE STACKED DATA**
********************************************************************************

if `switch_rerun_stacking'{
	do "${main}/code/build_stacked_data.do"
}

********************************************************************************
**COMPLETIONS DATA**
********************************************************************************

use "${main}/data/outcomes_completions_cip_all.dta", clear

	local type ""
	
if `switch_nponly'{
	drop if control == 3
	local type  "_nponly`type'"
}
if `switch_fponly'{
	keep if control == 3
	local type  "_fponly`type'"
}
if `switch_pubonly'{
	keep if control == 1
	local type  "_public`type'"
}
if `switch_post00'{
	keep if file_year >= 2000
	local type  "_post00`type'"
}

else if `switch_all'{
	local type = "_all"
}
		
//keep only associate degree totals
keep if deg == 3

//collapse by state
collapse (sum) cbkaa`pop' chisp`pop' cwhit`pop' , by(file_year deg st_fips)
	drop if st_fips > 56 //this drops all of the US territories
	drop if file_year < 1995 // this drops years before 1995 because race reporting didn't start until '95
	
if `switch_controls'{
	//generate indicators for if a state has a free CC program in a given year
	gen free_cc = 0
		replace free_cc = 1 if st_fips == 5  & file_year > 2016
		replace free_cc = 1 if st_fips == 6  & file_year > 2018
		replace free_cc = 1 if st_fips == 9  & file_year > 2019
		replace free_cc = 1 if st_fips == 10 & file_year > 2005
		replace free_cc = 1 if st_fips == 13 & file_year > 2013
		replace free_cc = 1 if st_fips == 15 & file_year > 2017
		replace free_cc = 1 if st_fips == 18 & file_year > 1990
		replace free_cc = 1 if st_fips == 19 & file_year > 2019
		replace free_cc = 1 if st_fips == 20 & file_year > 2016
		replace free_cc = 1 if st_fips == 21 & file_year > 2016
		replace free_cc = 1 if st_fips == 22 & file_year > 2016
		replace free_cc = 1 if st_fips == 24 & file_year > 2016
		replace free_cc = 1 if st_fips == 28 & file_year > 2016
		replace free_cc = 1 if st_fips == 29 & file_year > 2016
		replace free_cc = 1 if st_fips == 30 & file_year > 2016
		replace free_cc = 1 if st_fips == 32 & file_year > 2016
		replace free_cc = 1 if st_fips == 34 & file_year > 2016
		replace free_cc = 1 if st_fips == 36 & file_year > 2016
		replace free_cc = 1 if st_fips == 40 & file_year > 2016
		replace free_cc = 1 if st_fips == 41 & file_year > 2016
		replace free_cc = 1 if st_fips == 44 & file_year > 2016
		replace free_cc = 1 if st_fips == 46 & file_year > 2016
		replace free_cc = 1 if st_fips == 47 & file_year > 2016
		replace free_cc = 1 if st_fips == 53 & file_year > 2016
		replace free_cc = 1 if st_fips == 54 & file_year > 2016
		
	//add controls for unemployment rate by state
	preserve
		use "${main}/data/clean_controls_labormarket.dta", clear
		
		keep statefips unemp_rate year
			rename statefips st_fips
			rename year file_year
		
		tempfile unemployment
		save `unemployment'
	restore 
	
	merge m:1 file_year st_fips using `unemployment', assert(match)	nogen
	
	rename file_year year_academic
	rename st_fips statefips 
		
	keep year_academic statefips deg cbkaa`pop' chisp`pop' cwhit`pop' free_cc unemp_rate
}
else{
	rename file_year year_academic
	rename st_fips statefips 
			
	keep year_academic statefips deg cbkaa`pop' chisp`pop' cwhit`pop' 
}

reshape wide cbkaa`pop' chisp`pop' cwhit`pop', i(year_academic statefips) j(deg)
foreach c in cbkaa`pop' chisp`pop' cwhit`pop'{
	gen log_`c' = ln(`c')
}


//locals
local var log_ctotal  //ctotal
local ytitle "log degree completions"

//merge in minimum wage data
merge 1:m year_academic statefips using "${main}/data/mw_stacked.dta", keep(match) // keep matches drops years outside of our enrollment panel


********************************************************************************
**GRAPHING**
********************************************************************************

matrix colcbkaa`pop' = J(8,2,.)
matrix colchisp`pop' = J(8,2,.)
matrix colcwhit`pop' = J(8,2,.)
matrix col1 = J(8,6,.)
matrix col2 = J(8,1,.)
matrix results = J(8,7,.)

* define treatment vector
global treat F*treat L*treat

*linear combinations of post-reg coeffs
global lincomm3 F3treat - F1treat
global lincomm2 F2treat - F1treat
global lincomm1 F1treat - F1treat
global lincom0 L0treat - F1treat
global lincom1 L1treat - F1treat
global lincom2 L2treat - F1treat
global lincom3 L3treat - F1treat
global lincom4 L4treat - F1treat


foreach c in cbkaa`pop' chisp`pop' cwhit`pop'{
	eststo `c':  reghdfe log_`c' $treat `controls' , ///
			a(i.event#i.statefips i.event#i.rel_time i.event#i.control_origeventpost ///
			i.event#control_fedeventpost i.event#control_othereventpost) cluster(dmw_statefips) 
				local dof = e(df_r)
				local i = 1
				foreach year in 3 2 1{
					lincom (${lincomm`year'})
						matrix col`c'[`i',1] = r(estimate)
						matrix col`c'[`i++',2] = r(se)
				}
				foreach year in 0 1 2 3 4{
					lincom (${lincom`year'})
						matrix col`c'[`i',1] = r(estimate)
						matrix col`c'[`i++',2] = r(se)
				}
}

matrix col1 = colcbkaa`pop', colchisp`pop', colcwhit`pop'
	matrix col2[1,1] = -3
	matrix col2[2,1] = -2
	matrix col2[3,1] = -1
	matrix col2[4,1] = 0
	matrix col2[5,1] = 1
	matrix col2[6,1] = 2
	matrix col2[7,1] = 3
	matrix col2[8,1] = 4
matrix results = col1, col2

clear
matlist results
svmat results

rename results1  coeff_black
rename results2  se_black
rename results3  coeff_hisp
rename results4  se_hisp
rename results5  coeff_white
rename results6  se_white
rename results7  time

foreach x in black hisp white{
	gen ci_upper_`x' = coeff_`x' + invttail(`dof', 0.025)*se_`x'
	gen ci_lower_`x' = coeff_`x' - invttail(`dof', 0.025)*se_`x'
}


//graphing style things
	grstyle init
	grstyle set plain
	grstyle set size 8pt: subheading axis_title

twoway rcap ci_upper_black ci_lower_black time, lcolor(dkorange%90) ||  ///
		connected coeff_black time, lcolor(dkorange%90) mcolor(dkorange%90) || ///
		rcap ci_upper_hisp ci_lower_hisp time, lcolor(navy%90) ||  ///
		connected coeff_hisp time, lcolor(navy%90) mcolor(navy%90) ||  ///
		rcap ci_upper_white ci_lower_white time, lcolor(gs8%80) ||  ///
		connected coeff_white time, lcolor(gs8%90) mcolor(gs8%80)  ///
	ylab(-.18(.04).12, grid labsize(small)) yscale(range(-.18 .12)) yline(0, lp(dash) lc(gs10)) xline(-1, lp(dash) lc(black)) ///
	xlab(-3(1)4, grid labsize(small)) legend(col(3) order(2 "Black" 4 "Hispanic" 6 "White") size(small)) ///
	ytitle("`ytitle'") xtitle("years since minimum wage change") legend(region(lstyle(none)))
		
graph export "${output}/MWcompAA_race`pop'_${dmwlevel}`type'`control_lab'.pdf", replace

	


